package com.dji.ux.sample.Utils;

import android.util.Log;

import com.dji.ux.sample.DJISampleApplication;

import dji.common.error.DJIError;
import dji.common.gimbal.Rotation;
import dji.common.gimbal.RotationMode;
import dji.common.util.CommonCallbacks;
import dji.sdk.gimbal.Gimbal;

public class GimbalUtil {
    private static String TAG = "GimbalUtil";

    public static void adjustGimbalPitch(float degree){
        try {
            Gimbal gimbal = DJISampleApplication.getProductInstance().getGimbal();
            if (gimbal != null){
                Rotation.Builder builder = new Rotation.Builder().mode(RotationMode.ABSOLUTE_ANGLE).time(0.5);
                builder.pitch(degree);
                gimbal.rotate(builder.build(), new CommonCallbacks.CompletionCallback() {
                    @Override
                    public void onResult(DJIError djiError) {
                        if (djiError != null) Log.d(TAG, "onResult: " + djiError.getDescription());
                    }
                });
            }else {
                Log.d(TAG, "Gimbal disconnect.");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void resetGimbal(){
        try {
            Gimbal gimbal = DJISampleApplication.getProductInstance().getGimbal();
            if (gimbal != null){
                gimbal.reset(new CommonCallbacks.CompletionCallback() {
                    @Override
                    public void onResult(DJIError djiError) {
                        if (djiError != null) Log.d(TAG, "onResult: " + djiError.getDescription());
                    }
                });
            }else {
                Log.d(TAG, "Gimbal disconnect.");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
